package com.hunktimes.wholesale.vm

import androidx.lifecycle.MutableLiveData
import com.hunktimes.wholesale.base.BaseViewModel
import com.hunktimes.wholesale.extension.launch
import com.hunktimes.wholesale.net.WholeSaleRepository
import com.hunktimes.wholesale.net.model.ApiResponse
import com.hunktimes.wholesale.net.model.Login
import com.hunktimes.wholesale.net.model.LoginOrReg

/**
 * Author: Delete
 * Date: 2020/8/10 9:45
 * Description:
 *
 */
class LoginVM : BaseViewModel() {

    val userName = MutableLiveData<String>("")
    val pwd = MutableLiveData<String>("")

    val loginResult = MutableLiveData<ApiResponse<String>>()

    fun login() {
        launch({
            val userName = userName.value!!
            val pwd = pwd.value!!
            val login = Login(
                userName = userName, pwd = pwd
            )
            val loginOrReg = LoginOrReg("", "")
            val loginRes = WholeSaleRepository.login(loginOrReg)
            loginRes?.let {
                loginResult.value = it
            }
        })
    }
}